package com.gitee.learning

import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        recyclerView.layoutManager = LinearLayoutManager(this)

        val data = ArrayList<Item>()
        data.add(Item(getString(R.string.event_test_title), Intent(this, EventTestActivity::class.java)))
        data.add(Item("xxx测试1", Intent()))
        data.add(Item("xxx测试2", Intent()))
        val myAdapter = MyAdapter(R.layout.activity_main_item, data)

        myAdapter.bindToRecyclerView(recyclerView)

        myAdapter.setOnItemClickListener { adapter, view, position ->
            startActivity((adapter.getItem(position) as Item).intent)
        }
    }

    class Item(
            var name: String,
            var intent: Intent
    ) {
    }

    class MyAdapter(layoutResId: Int, data: MutableList<Item>) : BaseQuickAdapter<Item, BaseViewHolder>(layoutResId, data) {
        override fun convert(helper: BaseViewHolder, item: Item) {
            helper.setText(R.id.name, item.name)
        }
    }
}
